﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace easyList.Logging
{
    class Logger
    {
        
        private static Logger instance;

        private Logger() { }


        public List<LogItem> logContent { get; set; }

        public LogWindow logWindow { get; set; }

        public static Logger Instance
       {
          get 
          {
             if (instance == null)
             {
                 instance = new Logger();
                 instance.logContent = new List<LogItem>();
             }
             return instance;
          }
       }

        public void DEBUG(string message)
        {
            this.logContent.Add(new LogItem(LogItem.Level.DEBUG, message));
            refreshLogWindow();
        }

        public void INFO(string message)
        {
            this.logContent.Add(new LogItem(LogItem.Level.INFO, message));
            refreshLogWindow();
        }

        public void ERROR(string message)
        {
            this.logContent.Add(new LogItem(LogItem.Level.ERROR, message));
            refreshLogWindow();
        }

        private void refreshLogWindow()
        {


            string logStr = "";
            foreach (LogItem current in logContent)
            {

                logStr = logStr + "[" + DateTime.Now + "][" + current.level + "] " + current.message + "\r\n";
            }

            this.logWindow.logOutputTextBox.Text = logStr;

        }

    }
}
